const Koa = require('koa')
const KoaRouter = require('koa-router')
const sendFile = require('koa-sendfile')
const path = require('path')
const mount = require('koa-mount');
const graphqlHTTP = require('koa-graphql');

const mysql = require('./db');

const app = new Koa()
const router = new KoaRouter()
const MyGraphQLSchema = require('./schema/default');

// Routes
router.get(`/`, async (ctx) => {
  const result = await mysql.query('select * from account');
  ctx.body = {
    code: 0,
    data: result,
  };
})

app.use(mount('/graphql', graphqlHTTP({
  schema: MyGraphQLSchema, // 待定数据
  graphiql: true
})));

app.use(router.allowedMethods()).use(router.routes());

// don't forget to export!
module.exports = app
